package com.example.demo.controller;

import com.example.demo.controller.bean.Result;
import com.example.demo.mapper.entity.Area;
import com.example.demo.mapper.entity.City;
import com.example.demo.mapper.entity.Province;
import com.example.demo.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Lucy
 * @create 2024-02-20 14:52
 */
@RequestMapping("region")
@Api(value = "省市区三级联动选择器", tags = {"省市区三级联动选择器接口"})
@RestController
@Slf4j
public class RegionController {

    @Autowired
    private RegionService service;
    @ApiOperation("获取省份列表")
    @RequestMapping("provinces")
    public Result<Object> buildProvinceList() {
        List<Province> list = service.buildProvinceList();
        return Result.ok(list);
    }
    @ApiOperation("获取省份对应的城市列表")
    @RequestMapping("cities/{provinceId}")
    public Result<Object> buildCitiesList(@PathVariable("provinceId") String provinceId) {
        List<City> list = service.buildCitiesListByProvinceId(provinceId);
        return Result.ok(list);
    }
    @ApiOperation("获取城市对应的区县列表")
    @RequestMapping("areas/{cityId}")
    public Result<Object> buildAreasList(@PathVariable("cityId") String cityId) {
        List<Area> list = service.buildAreasListByCityId(cityId);
        return Result.ok(list);
    }
}
